﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ahp;

namespace AhpTest
{
    [TestClass]
    public class AlternativeNodeCollectionTest
    {
        [TestMethod]
        public void AddAlternativeNodeTest()
        {
            AlternativeNodeCollection alternativeNodes = new AlternativeNodeCollection();
            AlternativeNode alternativeNode = new AlternativeNode(new Alternative("Alternative"));

            int index = alternativeNodes.Add(alternativeNode);

            Assert.AreEqual(0, index);
            Assert.AreEqual(alternativeNode, alternativeNodes[index]);

            //no repeated elements
            index = alternativeNodes.Add(alternativeNode);
            Assert.AreEqual(0, index);
            Assert.AreEqual(1, alternativeNodes.Count);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void AddDuplicatedAlternativeTest()
        {
            AlternativeNodeCollection alternativeNodes = new AlternativeNodeCollection();
            Alternative alternative = new Alternative();

            AlternativeNode alternativeNode1 = new AlternativeNode(alternative);
            alternativeNodes.Add(alternativeNode1);

            AlternativeNode alternativeNode2 = new AlternativeNode(alternative);
            alternativeNodes.Add(alternativeNode2);
        }

        [TestMethod]
        public void RemoveAlternativeNodeTest()
        {
            AlternativeNodeCollection alternativeNodes = new AlternativeNodeCollection();
            AlternativeNode alternativeNode = new AlternativeNode(new Alternative());

            alternativeNodes.Add(alternativeNode);
            Assert.IsTrue(alternativeNodes.Contains(alternativeNode));

            alternativeNodes.Remove(alternativeNode);
            Assert.IsFalse(alternativeNodes.Contains(alternativeNode));
        }

        [TestMethod]
        public void ClearAlternativeNodesTest()
        {
            AlternativeNodeCollection alternativeNodes = new AlternativeNodeCollection();
            AlternativeNode alternativeNode1 = new AlternativeNode(new Alternative());
            AlternativeNode alternativeNode2 = new AlternativeNode(new Alternative());

            alternativeNodes.Add(alternativeNode1);
            alternativeNodes.Add(alternativeNode2);
            Assert.AreEqual(2, alternativeNodes.Count);

            alternativeNodes.Clear();
            Assert.AreEqual(0, alternativeNodes.Count);
        }

        [TestMethod]
        public void AlternativeIndexerTest()
        {
            AlternativeNodeCollection alternativeNodes = new AlternativeNodeCollection();

            Alternative alternative1 = new Alternative();
            AlternativeNode alternativeNode1 = new AlternativeNode(alternative1);
            alternativeNodes.Add(alternativeNode1);

            Alternative alternative2 = new Alternative();
            AlternativeNode alternativeNode2 = new AlternativeNode(alternative2);
            alternativeNodes.Add(alternativeNode2);

            Assert.AreEqual(alternativeNode1, alternativeNodes[alternative1]);
            Assert.AreEqual(alternativeNode2, alternativeNodes[alternative2]);
        }

        [TestMethod]
        public void ContainsWithAlternativeTest()
        {
            AlternativeNodeCollection alternativeNodes = new AlternativeNodeCollection();

            Alternative alternative1 = new Alternative();
            AlternativeNode alternativeNode1 = new AlternativeNode(alternative1);
            alternativeNodes.Add(alternativeNode1);

            Alternative alternative2 = new Alternative();
            AlternativeNode alternativeNode2 = new AlternativeNode(alternative2);
            alternativeNodes.Add(alternativeNode2);

            Alternative alternative3 = new Alternative();

            Assert.IsTrue(alternativeNodes.ContainsWithAlternative(alternative1));
            Assert.IsTrue(alternativeNodes.ContainsWithAlternative(alternative2));
            Assert.IsFalse(alternativeNodes.ContainsWithAlternative(alternative3));
        }
    }
}
